package string_question.leecode.test44;

import org.junit.Test;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/7 10:16
 */
public class Solution1 {

    // 动态规划求解
    public boolean isMatch(String s, String p) {
        if (p.equals("")) return s.equals("");
        int n1 = s.length();
        int n2 = p.length();
        boolean[][] dp = new boolean[n1 + 1][n2 + 1];
        dp[0][0] = true;
        for (int i = 1; i <= n2; i++) {
            if (p.charAt(i - 1) == '*') {
                dp[0][i] = dp[0][i - 1];
            }
        }
        for (int i = 1; i <= n1; i++) {
            for (int j = 1; j <= n2; j++) {
                if (s.charAt(i - 1) == p.charAt(j - 1) || p.charAt(j - 1) == '?') {
                    dp[i][j] = dp[i - 1][j - 1];
                } else if (p.charAt(j - 1) == '*') {
                    dp[i][j] = dp[i][j - 1] || dp[i - 1][j] || dp[i - 1][j - 1];
                }
            }
        }
        return dp[n1][n2];
    }

    @Test
    public void test(){
        System.out.println(isMatch("adceb", "*a*b"));
    }

}
